package com.qufadai.btce.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Cache {

	private Map<String, Object> map = null;

	public Cache() {
		map = new HashMap<String, Object>();
	}

	public Cache(int size) {
		map = new HashMap<String, Object>(size);
	}

	public void clear() {
		map.clear();
	}

	public boolean containsKey(Object key) {
		return map.containsKey(key);
	}

	public Object get(Object key) {
		return map.get(key);
	}

	public boolean isEmpty() {
		return map.isEmpty();
	}

	public Set<String> keySet() {
		return map.keySet();
	}

	public void put(String key, Object value) {
		map.put(key, value);
	}

	@SuppressWarnings("rawtypes")
	public void remove(Object key) {
		Object o = map.remove(key);
		if (o != null) {
			if (o instanceof List) {
				((List) o).clear();
			} else if (o instanceof Map) {
				((Map) o).clear();
			}
			o = null;
		}
	}

	public int size() {
		return map.size();
	}

	public Set<Entry<String, Object>> entrySet() {
		return map.entrySet();
	}

	public Collection<Object> values() {
		return map.values();
	}
}
